angular.module('starter')
.controller("selectDoctorsCtrl", function ($scope, $stateParams, appBase, httpService) {

    var deId = $stateParams.deId || "";
    var deName = $stateParams.deName || "";
    $scope.deName = deName;
    var deOffices = angular.fromJson(localStorage.getItem("hospitalOffices" + appBase.hospitalCode)) || [];
    if (deOffices.findIndex(x=>x.name == deName)<0)
    {
        deOffices.push({ "name": deName, "code": deId });
        localStorage.setItem("hospitalOffices" + appBase.hospitalCode, angular.toJson(deOffices));
    }


	//模拟医生数据
    $scope.dataDoctor = [];
	$scope.sortType = [
		{"sort_code":"0","sort_name":"综合排序"},
		{"sort_code":"1","sort_name":"热门排序"},
		{"sort_code":"2","sort_name":"推荐排序"},
		{"sort_code":"3","sort_name":"智能排序"}
	]
	$scope.sortRes = "综合排序";
	$scope.sortValue = "0";
	$scope.sortBol = false;
	$scope.conditionBol = true;
	
	$scope.title = 'aged';
	$scope.desc = 0;
	$scope.agedbol = true;
	$scope.numbol = true;
	$scope.index = 0;
	
	$scope.conditionFn = function(idx){
		$scope.index = idx;
		//热门排序
		if(idx==0){
			if($scope.conditionBol){
				$scope.sortBol = true;
				$scope.conditionBol = false;
			}else{
				$scope.sortBol = false;
				$scope.conditionBol = true;
			}
		}else{
			$scope.sortBol = false;
			$scope.conditionBol = true;
		}
		//医龄排序
		if(idx==1){
			$scope.title='aged';
			console.log($scope.desc)
			if($scope.agedbol){
				$scope.desc = 1;
				$scope.agedbol = false;
				
			}else{
				$scope.desc = 0;
				$scope.agedbol = true;
			}
		}
		//号源排序
		if(idx==2){
			$scope.title='num';
			console.log($scope.desc)
			if($scope.numbol){
				$scope.desc = 1;
				$scope.numbol = false;
				
			}else{
				$scope.desc = 0;
				$scope.numbol = true;
			}
		}
		
	}
	$scope.selectType = function($event){//选排序类型
		var thisTarget = $event.target;
		$scope.sortValue = thisTarget.attributes[1].value;
		$scope.sortRes = thisTarget.innerText;
		$scope.sortBol = false;
		$scope.conditionBol = true;
	}
	
    // 医院科室医生数据
	function loadDoctor() {
	    $scope.dataDoctor = [];
 
	    var parData = "?hospitalCode=" + appBase.hospitalCode + "&deptId=" + deId + "&sort=" + $scope.sortValue;
	    httpService.get(httpService.appWebApi.getDeDoctor + parData
          ).then(
          function (success) {
              var data = success.data;
              if (data.returnCode != "0") {
                  console.log(data.returnMsg)
                  return;
              }
              angular.forEach(data.returnData, function (modal) {
                  //实时在线
                  //$scope.dataDoctor.push({
                  //    "doctorName": modal.doctorInfo.doctorName,
                  //    "doctorId": modal.doctorInfo.doctorId,
                  //    "doctorRemark": modal.doctorInfo.doctorRemark,
                  //    "doctorGender": modal.doctorInfo.doctorGender,
                  //    "betterFor": modal.doctorInfo.betterFor,
                  //    "urlPic": modal.doctorInfo.urlPic,
                  //    "visitTimeInfo": modal.doctorInfo.visitTimeInfo,
                  //    "visitTimeInfo": modal.doctorInfo.visitTimeInfo,
                  //    "doctorTitle": modal.doctorInfo.doctorTitle,
                  //    "deptId": modal.doctorInfo.deptId,
                  //    "deptName": modal.doctorInfo.deptName,
                  //    "branchName": modal.doctorInfo.branchName,
                  //});
                  $scope.dataDoctor.push({
                      "doctorName": modal.doctorName,
                      "doctorId": modal.doctorId,
                      "doctorRemark": modal.doctorRemark,
                      "doctorGender": modal.doctorGender,
                      "betterFor": modal.betterFor,
                      "urlPic": modal.urlPic,
                      "visitTimeInfo": modal.visitTimeInfo,
                      "doctorTitle": modal.doctorTitle,
                      "deptId": modal.deptId,
                      "deptName": modal.deptName,
                      "hospitalName": modal.hospitalName,
                      "hsp_Code": modal.hsp_Code
                  });
              });
          }
          , function (error) {
              console.log(error);
          }).finally(function () {

          });
	}

	$scope.$watch('$viewContentLoaded', function () {
	    // 你的代码
	    loadDoctor();
	});
	
})
